﻿using System.Xml.Linq;
using PengSW.NotifyPropertyChanged;
using PengSW.XmlHelper;
using static PengSW.XmlHelper.XmlLinqHelper;

namespace ProtocolAnalyzer
{
    public class PreDefine : NotifyPropertyChangedObject, IXmlSeriable
    {
        public string Name { get => _Name; set { SetValue(ref _Name, value, nameof(Name)); } }
        private string _Name = "未命名";

        public string Value { get => _Value; set { SetValue(ref _Value, value, nameof(Value)); } }
        private string _Value;

        public void ReadFromXml(XElement aXElement)
        {
            if (aXElement == null) return;
            Name = aXElement.GetAttributeValue(nameof(Name), "未命名");
            Value = aXElement.Value;
        }

        public XElement CreateXElement(string aXmlNodeName)
        {
            return new XElement(aXmlNodeName, CreateXAttribute(nameof(Name), Name), new XCData(Value));
        }
    }
}
